<template>
  hello
</template>

<script lang="ts" setup>
//简单类型
let a:number  = 21
let b:string = 'hello'
let c:boolean = true
let d:null = null //null类型只能是null
let e:undefined = undefined //undefined类型只能是undefined
//数组类型 注解: number[] 或者 Array<number>
// let arr:number[]=[1,2,3]
let arr:Array<number>=[1,2,3]
// arr.push("a")
arr.forEach(item=>{
  // console.log(item.toFixed(2))
})
//联合类型
let arr2:(number|string)[] = [12,'hello']
arr2.forEach(item=>{
  console.log(item)
})

//类型别名
type ArrayType =(number|string)[]
let arr3:ArrayType = [12,'hello']

//函数类型
function sum(a:number,b:number){
  return a+b;
}
let result = sum(1,2)
console.log(result)

//箭头函数
let sum2 = (a:number,b:number)=>{
  return a+b;
}
let result2 = sum2(1,2)
console.log(result2)

//可选参数
function getFullName(firstName:string,lastName?:string){
  if (lastName){
    return `${firstName}${lastName}`
  }else {
    return firstName
  }
}
console.log(getFullName('张','三'))
console.log(getFullName('诸葛'))


//接口类型
interface Person{
  name:string;
  age:number;
  show:(msg:string)=>void;
}
let p:Person = {
  name:'张三',
  age:18,
  show(msg){
    console.log(msg)
  }
}
p.show('hello')
console.log(p.name)
console.log(p.age)

interface GoodsType{
  name:string;
  price:number;
}
interface DisGoodsType{
  disPrice:number;
}




</script>

<style>

</style>
